/**
 * zbestpayment.com Inc.
 * Copyright (c) 2004-2017 All Rights Reserved.
 */
package com.zbest.zpay.gw.dispatch;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zbest.zpay.gw.cache.CommunicationConfigCache;
import com.zbest.zpay.gw.dal.model.GwCommunicationConfigDO;
import com.zbest.zpay.gw.model.MessageContext;
import com.zbest.zpay.gw.model.ProtocolType;

/**
 * 
 *
 * @author Administrator
 * @version $Id: CommunicationAdaptorImpl.java, v 0.1 2017-4-12 下午11:27:28 Administrator Exp $
 */
@Service("messageDispatcherManager")
public class MessageDispatcherManager {

    @Resource
    private CommunicationConfigCache communicationConfigCache;

    @Resource
    private MessageDispatcher        httpMessageDispatcher;

    @Resource
    private MessageDispatcher        tcpMessageDispatcher;

    /**
     * 
     * @see com.zbest.zpay.gw.dispatch.MessageDispatcherManager#send(com.zbest.zpay.gw.model.MessageContext)
     */
    public void send(MessageContext context) {

        GwCommunicationConfigDO communicationConfigDO = communicationConfigCache.get(context
            .getChannelId());
        if (communicationConfigDO.getProtocolType().equals(ProtocolType.HTTP.name())
            || communicationConfigDO.getProtocolType().equals(ProtocolType.HTTPS.name())) {
            httpMessageDispatcher.send(context);
        } else if (communicationConfigDO.getProtocolType().equals(ProtocolType.TCP.name())) {
            tcpMessageDispatcher.send(context);
        } else {
            throw new UnsupportedOperationException();
        }

    }
}
